<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String id = request.getParameter("id") == null ? "" : request.getParameter("id");
    boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>

<html>
	<head>
		<title><%=isAdd?"新建供应商":"编辑供应商" %></title>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	</head>
	<script type="text/javascript">	
		var flag = '<%=flag%>';
		$(function(){
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=2',
				method:'POST',
				animate:true,
				lines:true
			});
			if(flag == '1'){
				$('#ff').form("load",'<%=contextPath %>/springMVC/crm/getSupplierById?id=<%=id%>');
				$('#finance_out_tr').hide();
			}
		});
		
		function doSubmit(obj){
			var type_id = $('#type_id').combotree('getValue');
			if(!checkNullOREmpty(type_id,"供应商分类")){return;}
			var company = $('#company').val();
			if(!checkNullOREmpty(company,"供应商名称")){return;}
			var contact = $('#contact').val();
			var tel = $('#tel').val();
			var fax = $('#fax').val();
			var mail = $('#mail').val();
			var finance_out = $('#finance_out').numberbox('getValue');
			if(!checkNullOREmpty(finance_out,"应付金额")){return;}
			var param = "type_id="+type_id+"&company="+company+"&contact="+contact+"&tel="+tel+"&fax="+fax+"&mail="+mail+"&finance_out="+finance_out;
			$(obj).hide();
			if(flag == '0'){
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/crm/addSupplier',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
			else{
				param=param+"&id=<%=id%>";
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/crm/updateSupplier',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
		}
		
	</script>
	<body>
		<form id="ff" method="POST">
		<div style="width:90%;padding-left:50px;margin-top:50px">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td align="right"  nowrap class="td1">
						分类：
					</td>
					<td class="td2" nowrap>
						<input  id="type_id" name="type_id" class="easyui-combotree"  data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						供应商名称：
					</td>
					<td class="td2" nowrap >
						<input type="text" id="company" name="company"  class="easyui-validatebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						联系人：
					</td>
					<td class="td2" nowrap >
						<input id="contact" name="contact"/>
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						TEL：
					</td>
					<td class="td2" nowrap >
						<input id="tel" name="tel" />
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						FAX：
					</td>
					<td class="td2" nowrap >
						<input id="fax" name="fax" />
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						MAIL：
					</td>
					<td class="td2" nowrap >
						<input id="mail" name="mail" />
					</td>
				</tr>
				<tr id="finance_out_tr">
					<td align="right"  nowrap class="td1">
						应付金额：
					</td>
					<td class="td2" nowrap >
						<input id="finance_out" name="finance_out" class="easyui-numberbox" data-options=" min:0,precision:2" value="0"/>
					</td>
				</tr>
				<tr>
					<td align="right" nowrap class="td1">
					</td>
					<td  nowrap colspan="5">
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
					</td>
				</tr>
				
 			</table>
		</div>
		</form>
	</body>
</html>
